package com.example.indenture.common;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * 登录拦截器
 *
 * @author CY
 * @date 2023/03/14 20:51
 **/
@Component
public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        final HttpSession session = request.getSession();
        if (session != null && session.getAttribute(Constant.SESSION_USERINFO_KEY) != null){
            //当前已经登录
            return true;
        }
        return true;
//        response.setStatus(401);
//        return false;
    }

}
